"""MxOnline URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.views.generic import TemplateView
from django.conf.urls import url, include
from django.views.decorators.csrf import csrf_exempt

from django.conf import settings
from django.views.static import serve

import xadmin

# version模块自动注册需要版本控制的 Model
from xadmin.plugins import xversion

from apps.users.views import LoginView, LogoutView, SendSmsView, DynamicLoginView, RegisterView
from apps.organiztion.views import OrgView

xversion.register_models()

xadmin.autodiscover()
urlpatterns = [
    path('admin/', admin.site.urls),
    path('xadmin/', xadmin.site.urls),
    path('', TemplateView.as_view(template_name='index.html'), name='index'),
    path('login/', LoginView.as_view(), name='login'),  # 普通登录
    path('register/', RegisterView.as_view(), name="register"),  # 注册
    path('d_login/', DynamicLoginView.as_view(), name="d_login"),  # 动态登录验证手机验证码
    path('logout/', LogoutView.as_view(), name='logout'),  # 注销登录
    path('captcha/', include('captcha.urls')),  # 图片验证码
    path('send_sms/', csrf_exempt(SendSmsView.as_view()), name='send_sms'),  # 动态登录验证图片验证码
    # 配置上传文件访问路经
    url(r'^media/(?P<path>.*)$', serve, {'document_root': settings.MEDIA_ROOT}),

    # 课程机构列表
    # path('org_list/', OrgView.as_view(), name='org_list'),  # 动态登录验证图片验证码
    url(r'^org/', include(('apps.organiztion.urls', 'organiztion'), namespace='org')),  # 使用 include 并添加命名空间时，必须在 include 中添加 app 名称参数

    # 用户操作相关
    url(r'^op/', include(('apps.operation.urls', 'operation'), namespace='op')),  # 使用 include 并添加命名空间时，必须在 include 中添加 app 名称参数
]
